using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

namespace ProxyServer.EntityFrameworkCore.ValueConverts;

public class DateTimeOffsetToTicksValueConverter : ValueConverter<DateTimeOffset, long>
{
    public DateTimeOffsetToTicksValueConverter() : base(
        v => ToTicks(v),
        v => ToDateTimeOffset(v))
    {
    }

    public static DateTimeOffset ToDateTimeOffset(long ticks)
    {
        return new DateTime(ticks).ToLocalTime();
    }

    public static long ToTicks(DateTimeOffset dateTimeOffset)
    {
        return dateTimeOffset.UtcTicks;
    }

    public static readonly DateTimeOffsetToTicksValueConverter Singleton = new DateTimeOffsetToTicksValueConverter();
}